home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
clonecd
/
September 93.img
/
Archives
/
Decoration
/
Screensavers
/
Screen Savers
/
TwilightZone
/
source
/
commands.c
< prev
next >
Wrap
Text File
|
1993-06-17
|
3KB
|
212 lines
/*-------------------------------------------------------------------------------------
*
* Simple Sample Application Framework
*
* ©1991 Apple Computer
*
-------------------------------------------------------------------------------------*/
/*
* commands.c -- called in response to menu commands or appleevents
*
* change history:
*
* SJF 11/6/91 1.0d1 initial coding
*
*/
#include <Script.h>
#include "const.h"
#include "strconst.h"
#include "mymenus.h"
#include "mytypes.h"
#include "globals.h"
#include "utils.h"
#include "windowstuff.h"
#include "commands.h"
/* closes a window */
void CommCloseWindow(WindowPtr window)
{
TInfoHndl infoHndl;
if (!IsAppWindow(window))
return;
infoHndl = GetWindowInfo(window);
SendWindowMessage(window,kDeactivateMessage,nil);
SendWindowMessage(window,kDestroyMessage,nil);
DisposHandleChk(infoHndl);
DisposeWindow(window);
}
/* processes edit menu commands */
void CommEdit(WindowPtr window,short command)
{
short msg;
if (!IsAppWindow(window))
return;
switch (command) {
case kUndoItem:
msg = kUndoMessage;
break;
case kCutItem:
msg = kCutMessage;
break;
case kCopyItem:
msg = kCopyMessage;
break;
case kPasteItem:
msg = kPasteMessage;
break;
case kClearItem:
msg = kClearMessage;
break;
default:
return;
}
SendWindowMessage(window,msg,nil);
}
/* processes print commands */
void CommPrint(WindowPtr window)
{
if (IsAppWindow(window))
SendWindowMessage(window,kPrintMessage,nil);
}
/* processes page setup commands */
void CommPageSetup(WindowPtr window)
{
if (IsAppWindow(window))
SendWindowMessage(window,kPageSetupMessage,nil);
}
/* show about box */
void CommAbout(void)
{
Alert(kAboutBoxDialog,nil);
}
/* new command */
void CommNew(void)
{
}
/* open command */
void CommOpen(void)
{
StandardFileReply sfReply;
SFTypeList typeList;
typeList[0] = kAppType;
StandardGetFile(nil,kNumAppTypes,typeList,&sfReply);
if (sfReply.sfGood) {
LoOpen(&sfReply.sfFile);
}
}
/* low-level open (can be called by aevt) */
void LoOpen(FSSpec *fSpec)
{
WindowPtr window;
TInfoHndl info;
short wType;
OSErr err;
FInfo fInfo;
void *message;
err = FSpGetFInfo(fSpec,&fInfo);
if (err!=noErr) {
DoError(err);
return;
}
switch (fInfo.fdType) {
case kAppType:
wType = kDimmerWindow;
break;
default:
DoError(kInternalError);
return;
}
window = MakeWindow(wType,nil,fSpec->name,true);
if (window) {
info = GetWindowInfo(window);
BlockMove(fSpec,&(*info)->fileSpec,sizeof(FSSpec));
SendWindowMessage(window,kLoadMessage,message);
}
}
/* save command */
void CommSaveFile(WindowPtr window)
{
TInfoHndl info;
if (!IsAppWindow(window))
return;
info = GetWindowInfo(window);
if (!(**info).changed)
return;
if (!(**info).saved)
CommSaveAsFile(window);
else
LoSaveFile(window);
}
/* save as command */
void CommSaveAsFile(WindowPtr window)
{
TInfoHndl info;
StandardFileReply sfReply;
OSErr err;
if (!IsAppWindow(window))
return;
info = GetWindowInfo(window);
StandardPutFile(kPromptString,kDefaultFilename,&sfReply);
if (sfReply.sfGood) {
BlockMove(&sfReply.sfFile,&((**info).fileSpec),sizeof(FSSpec));
LoSaveFile(window);
}
}
/* low-level save file */
void LoSaveFile(WindowPtr window)
{
SendWindowMessage(window,kSaveMessage,nil);
}